package com.rygl.staff.service.impl;

import java.util.List;
import com.rygl.common.utils.DateUtils;
import com.rygl.staff.domain.*;
import com.rygl.staff.domain.Vo.EmployeeDocumentsVo;
import com.rygl.staff.domain.Vo.SalarySocialVO;
import com.rygl.staff.domain.Vo.StaffVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rygl.staff.mapper.StaffMapper;
import com.rygl.staff.service.IStaffService;

/**
 * 员工基础信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-06
 */
@Service
public class  StaffServiceImpl implements IStaffService
{
    @Autowired
    private StaffMapper staffMapper;

    /**
     * 查询员工基础信息
     * 
     * @param id 员工基础信息主键
     * @return 员工基础信息
     */
    @Override
    public StaffVO selectStaffById(Long id)
    {
        //  查询员工基础信息
        Staff staff = staffMapper.selectStaffById(id);
        StaffVO staffVo = new StaffVO();
        // 拷贝属性
        BeanUtils.copyProperties(staff,staffVo);
        //  查询员工基础信息关联信息
        List<EducationExperience> educationExperiences=staffMapper.selectEducationExperiences(id);
        List<Certificate> certificates=staffMapper.selectCertificates(id);
        List<WorkExperience> workExperiences=staffMapper.selectWorkExperiences(id);
        List<TrainingExperience> trainingExperiences=staffMapper.selectTrainingExperiences(id);
        /// 设置关联信息
        staffVo.setEducationExperiences(educationExperiences);
        staffVo.setCertificates(certificates);
        staffVo.setWorkExperiences(workExperiences);
        staffVo.setTrainingExperiences(trainingExperiences);
        return staffVo;
    }

    /**
     * 查询员工基础信息列表
     * 
     * @param staff 员工基础信息
     * @return 员工基础信息
     */
    @Override
    public List<Staff1> selectStaffList(Staff1 staff)
    {
        return staffMapper.selectStaffList(staff);
    }

    /**
     * 新增员工基础信息
     * 
     * @param staff 员工基础信息
     * @return 结果
     */
    @Override
    public int insertStaff(Staff1 staff)
    {
        staff.setCreateTime(DateUtils.getNowDate());
        return staffMapper.insertStaff(staff);
    }

    /**
     * 修改员工基础信息
     * 
     * @param staff 员工基础信息
     * @return 结果
     */
    @Override
    public int updateStaff(Staff1 staff)
    {
        staff.setUpdateTime(DateUtils.getNowDate());
        return staffMapper.updateStaff(staff);
    }

    /**
     * 批量删除员工基础信息
     * 
     * @param ids 需要删除的员工基础信息主键
     * @return 结果
     */
    @Override
    public int deleteStaffByIds(Long[] ids)
    {
        return staffMapper.deleteStaffByIds(ids);
    }

    /**
     * 删除员工基础信息信息
     * 
     * @param id 员工基础信息主键
     * @return 结果
     */
    @Override
    public int deleteStaffById(Long id)
    {
        return staffMapper.deleteStaffById(id);
    }

    /**
     * 查询员工基础信息关联岗位信息
     *
     * @param id 员工基础信息主键
     * @return 员工基础信息
     */
    @Override
    public JobAssignment selectjobById(Long id) {
        return staffMapper.selectJobById(id);
    }

    @Override
    public SalarySocialVO selectSalaryById(Long id) {
        SalarySocialVO salarySocialVO = staffMapper.selectSalaryById(id);
        List<SalaryRecords> selectSalaryRecords=staffMapper.selectSalaryRecordsById(id);
        salarySocialVO.setSalaryRecords(selectSalaryRecords);
        return salarySocialVO;
    }

    @Override
    public List<EmployeeDocumentsVo> selectDocumentsById(Long id, Integer type) {
        List<EmployeeDocumentsVo> employeeDocumentsVos= staffMapper.selectDocumentsByEmployeeId(id,type);
        for (EmployeeDocumentsVo employeeDocumentsVo : employeeDocumentsVos) {
            String[] split = employeeDocumentsVo.getFilePath().split("/");
            employeeDocumentsVo.setFileName(split[split.length-1]);
        }
        return employeeDocumentsVos;
    }

    @Override
    public List<StaffOperationLog> selectOperationLog(Long id) {
        List<StaffOperationLog> staffOperationLogs = staffMapper.selectOperationLogByUserId(id);
        return staffOperationLogs;
    }

    @Override
    public List<StaffTransferLog> selectStaffTransferLog(Long id) {
        List<StaffTransferLog> staffTransferLogs = staffMapper.selectTransferLogByUserId(id);
        return staffTransferLogs;
    }

    @Override
    public List<EmploymentContract> selectStaffContract(Long id) {
        List<EmploymentContract> employmentContracts = staffMapper.selectStaffContract(id);
        return employmentContracts;
    }


}
